﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SampleMessages;
using SimpleServiceBus.Bus.MessageManagement.MessageHandling;
using SimpleServiceBus.Bus.Pipeline;

namespace SampleConfiglessEndpoint
{
    public class TestPublicationMessageHandler : IMessageHandler<TestPublicationMessage>

    {
        public void Handle(TestPublicationMessage message, IMessageContext context)
        {
            MainForm.Current.Notify("Publication Received from " + context.MessageEnvelope.ReturnAddress + ":" + message.Message + " sent at " + message.EventTime);
            if (context.MessageEnvelope.RetryCount < 2)
                throw new Exception(string.Format("Ouch! An Exception! It's OK, I threw this on purpose...I have failed {0} times and will stop failing at 2.",context.MessageEnvelope.RetryCount + 1));
        }
    }
}
